package com.cpi.basilos.reason.movement.service;

import org.apache.log4j.Logger;

import com.cpi.basilos.reason.movement.converter.ReasonMovementConverter;
import com.cpi.basilos.reason.movement.dao.ReasonMovementDAO;
import com.cpi.basilos.reason.movement.dto.ReasonMovementDTO;
import com.cpi.basilos.reason.movement.exception.ReasonMovementException;
import com.cpi.basilos.reason.movement.view.ReasonMovementView;
import com.cs.common.exception.CSException;

public class ReasonMovementService {
	private static org.apache.log4j.Logger logger = Logger.getLogger(ReasonMovementService.class);
	
	public ReasonMovementView getReasonMovement(String reasonMovementCode)throws ReasonMovementException{
		ReasonMovementView reasonMovementView = null;
		ReasonMovementDAO reasonMovementDAO = null;
		ReasonMovementDTO reasonMovementDTO = null;
		ReasonMovementConverter reasonMovementConverter = null;
		try{
			reasonMovementDAO = new ReasonMovementDAO();
			reasonMovementConverter = new ReasonMovementConverter();
			reasonMovementDTO = reasonMovementDAO.getReasonMovement(reasonMovementCode);
			reasonMovementView = reasonMovementConverter.convertDTOToView(reasonMovementDTO);
		}catch(ReasonMovementException reasonMovementException){
			throw reasonMovementException;
		}catch(Exception exception){
			ReasonMovementException reasonMovementException = null;
			exception.printStackTrace(System.out);
			logger.error(exception);
			reasonMovementException = new ReasonMovementException(exception, CSException.LAYER_SERVICE, CSException.ACTION_SELECT);
			throw reasonMovementException;
		}
		return reasonMovementView;
	}
}